﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Chess
{
    public class King:InterfacePiece
    {
        Piece piece = null;
        
        public King(Piece King)
		{
			piece = King;
		}      
      
        public int ImageIndex
        {
            get {return (this.piece.Player.isColor == Player.Color.WHITE ? 10 : 11); }
        }       

        public void SetPosition(Moves moves)
        {
            Square square;

            square = Board.GetSquare(piece.Square.Ordinal + 17);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor!= piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);

            square = Board.GetSquare(piece.Square.Ordinal - 17);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor!= piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);
   
            square = Board.GetSquare(piece.Square.Ordinal + 16);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor!= piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);

            square = Board.GetSquare(piece.Square.Ordinal - 16);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor!= piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);

            square = Board.GetSquare(piece.Square.Ordinal + 15);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor!= piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);

            square = Board.GetSquare(piece.Square.Ordinal - 15);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor!= piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);         
            
            square = Board.GetSquare(piece.Square.Ordinal + 1);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor!= piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);

            square = Board.GetSquare(piece.Square.Ordinal - 1);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor!= piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);
        }
    }
}
